<?php
/**
 * 描述:控制层共享文件, 控制层文件与类名相同, 已$_GET['a']作为方法名(默认index)
 * 作者:Edgar.lee
 */
require dirname(dirname(__FILE__)) . '/include/of/of.php';

//判断code是否为空
if(!empty($_GET['code'])){
    //调用接口，获取授权
    $token = of_base_com_kv::get('accreditAccount');
    $token = json_decode($token,true);
    p($token);
    $re = serv_rapi_wishU::codeToken($_GET['code'],$token['appKey'],$token['appSecret']);
    p($re);
    $data = [
        'account' => $token['account'],
        'appKey' => $token['appKey'],
        'appSecret' => $token['appSecret'],
        'accessToken' => $re['access_token'],
        'refreshToken' => $re['refresh_token'],
        'invalidDate' => date('Y-m-d H:i:s', $re['expiry_time']),
        'type' => $token['type'],
        'data' => $re
    ];
    core_base::trans(null);                                                     //开启事务
    core_account::setAccount($data);
    $res = core_base::trans(true);                                              //提交事务
    if($res['state']){
        echo '授权成功,请关闭';
    } else {
        echo '授权失败，请重试';
    }
}

return true;